<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ page import="com.google.appengine.api.users.User" %>
<%@ page import="com.google.appengine.api.users.UserService" %>
<%@ page import="com.google.appengine.api.users.UserServiceFactory" %>
<%@ page import="java.util.List" %>
<%@ page import="java.util.Iterator" %>
<%@ page import="studystat.*" %>

<html>
	<head>
	<%
    	UserService userService = UserServiceFactory.getUserService();
    	User user = userService.getCurrentUser();
	%>
		<title>Achievement!</title>
		<link rel="stylesheet" href="customThemeJ/themes/StudyStatTheme1.min.css" />
		<link rel="stylesheet" href="http://code.jquery.com/mobile/1.0rc2/jquery.mobile.structure-1.0rc2.min.css" />
			
		<script src="http://code.jquery.com/jquery-1.7.1.js"></script> 
		<script src="http://code.jquery.com/mobile/1.0rc2/jquery.mobile-1.0rc2.min.js"></script>
		<script type="text/javascript">
			
			$(document).ready(function(){
				
			});
			
		</script>
			
	</head>
<body>
<div data-role="page" data-theme="b">

	<!-- Titelbalk -->
	<div data-role="header" data-position="inline" data-theme="b">
	<a href="" data-icon="star" class="ui-btn-left" rel="external">Achievements</a>
	<h1>The Real Study Stat</h1>
	<a href="option.jsp" data-icon="gear" class="ui-btn-right" rel="external">Options</a>
	<div data-role="navbar">
		<ul>
			<li><a href="main.jsp" rel="external">Home</a></li>
			<li><a href="statistieken.jsp" rel="external">Statistieken</a></li>
			<li><a href="contact.html" rel="external">Contact</a></li>
			<li><a href="about.html" rel="external">Over Ons</a></li>
			<li><a href="<%= userService.createLogoutURL("/login") %>" rel="external">Uitloggen</a></li>
		</ul>
	</div>
	</div>
	
	<!-- Content -->
	<%
    	if (user != null) {
	%>
	<div data-role="content" id="content">
	<div class="ui-grid-b">
	<div class="ui-block-a"></div>
	<div class="ui-block-b">
		<h2>Jouw achievements</h2>
		<div>
		<script type="text/javascript">
			<%  
			List<Achievement> it = StudentManager.getInstance().getStudent(user.getUserId()).getAchievements();
			List<Achievement> list = AchievementManager.getInstance().getMogelijkeAchievements();
			%>
			var jslist = new Array();
			var javalistsize = <%= it.size() %>;
			<%
			for(int i = 0; i<it.size(); i++){
				%> jslist[<%= i %>] = <%= it.get(i) %>;<%
			}
			String behaalde = "";
			String nogniet = "<font color='gray'> Deze titels heb je nog niet verdiend: </br> </br>";
			for(Achievement ach : list){
				if(it.contains(ach)){
				behaalde += "Je hebt de titel \"" + ach.getTitel() + "\" verdiend! </br>";
				behaalde += "&nbsp;&nbsp;&nbsp;&nbsp;" + ach.getNaam() + "</br> </br>";
				}
				else {
				nogniet += ach.getTitel() + "</br>";
				nogniet += "&nbsp;&nbsp;&nbsp;&nbsp;" + ach.getNaam() + "</br> </br>";
				}
			}
			nogniet += "</font>";
			%>
			</script>
			<%= behaalde + nogniet %></div>
	</div>
	<div class="ui-block-c"></div>
	</div>
	<%}
	else {
		%>
		<div data-role="content" id="content">
		<p><a href="<%= userService.createLoginURL(request.getRequestURI()) %>">Log in om verder te gaan</a></p>
		</div>
	<%
	}%>
</div>
</div>
</body>
</html>